package com.example.demo.controller;

import com.example.demo.server.ComputerMesServer;
import org.apache.juli.FileHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;

@RestController
public class NetController {
	@Autowired
	ComputerMesServer computerMesServer;
	@GetMapping("/net")
	public String net() throws Exception {
		Logger logger=Logger.getLogger(NetController.class.toString());
		StringBuffer logPath=new StringBuffer();
		logPath.append("/root/service/log/net");     //设置保存路径

		//设置文件名
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		logPath.append("/"+sdf.format(new Date())+".log");

		//将输出handler加入logger
		try {
			logPath.toString();FileHandler fileHandler=new FileHandler(logPath.toString(),"net-",".log",30);

			logger.addHandler(fileHandler);
		}catch (Exception e){
			e.printStackTrace();
		}
		String message = computerMesServer.net();
		System.out.println("net 数据 ："+message);
		logger.info("net 数据 ："+message);
		return message;
	}
}
